package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.LocalAttrHelper;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.ExtendedPeriodAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 *
 */
@Service
@AttrHandler(ExtendedPeriodAttrHandler.class)
public class ExtendedPeriodAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Autowired
    private OperateInstAttrService operateInstAttrService;

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        KiteAttr startTimeAttr = inst.getAttr("210003980");
        KiteAttr endTimeAttr = inst.getAttr("210003981");
        if (KiteStringUtils.isNotEmpty(attr.getValue())) {
            if (Objects.nonNull(startTimeAttr)) {
                startTimeAttr.setIsNull(KeyConsts.IFTRUE_F);
            }
            if (Objects.nonNull(endTimeAttr)) {
                endTimeAttr.setIsNull(KeyConsts.IFTRUE_F);
                endTimeAttr.setIsEdit(KeyConsts.IFTRUE_F);
            }
            LocalAttrHelper.showAndNotNull(inst, "200004107");
            LocalAttrHelper.showAndNotNull(inst, "200004108");
        } else {
            if (Objects.nonNull(startTimeAttr)) {
                startTimeAttr.setIsNull(KeyConsts.IFTRUE_T);
            }
            if (Objects.nonNull(endTimeAttr)) {
                endTimeAttr.setIsNull(KeyConsts.IFTRUE_T);
                endTimeAttr.setIsEdit(KeyConsts.IFTRUE_T);
            }
            LocalAttrHelper.hideAndNullable(inst, "200004107");
            LocalAttrHelper.hideAndNullable(inst, "200004108");
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
